Fix: Support complete multihash type mappings in Prefix#76
Conversation
4231e10 to
7d07d6c
Compare
|
Thanks for the excellent contribution, @sumanjeet0012! This is another valuable improvement that simplifies the implementation while making This not only resolves the immediate issue with algorithms such as With the linting fixes included and the full CI matrix passing successfully across all supported environments, this change looks solid. Overall, this improves interoperability across the multiformats ecosystem while reducing maintenance burden. LGTM, thanks for the thoughtful implementation and happy to merge. CCing @acul71, @johannamoran, @mishmosh. |
Closes #65
Description
This PR addresses the issue where
Prefix._mh_types_to_code()andPrefix._mh_code_to_type()were using a hardcoded, incomplete mapping of only 8 multihash types, which led toValueErroron valid multihashes likeidentity,shake-256, andblake3.The mapping logic now properly delegates to the
multihashlibrary which acts as the source of truth for all supported multiformat hash codes.Changes
cid/prefix.pyfor both_mh_types_to_codeand_mh_code_to_type._mh_type_to_codenow usesmultihash.Funcandmultihash.coerce_code()to look up the type name safely._mh_code_to_typenow converts the code back to the canonical name viamultihash.Func.This enables py-cid to parse and serialize any valid prefix supported by python-multihash.